package br.com.academia.controller;

import java.sql.SQLException;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import br.com.academia.DAO.DAOGenerico;
import br.com.academia.beans.Aluno;
import br.com.academia.util.ConnectionFactory;

@Controller
public class AlunoController {
	
	@RequestMapping("/inserirAluno")
	public String cadastrarAluno(Aluno aluno) throws SQLException, Exception {
		new DAOGenerico<Aluno>(new ConnectionFactory().getConnection()).cadastrar(aluno);
		return "redirect:frmAluno";
	}
	
	@RequestMapping("/alterarAluno")
	public String alterarAluno(Aluno aluno) throws SQLException, Exception {
		new DAOGenerico<Aluno>(new ConnectionFactory().getConnection()).alterar(aluno, "idAluno");
		return "forward:pesquisaAvancada?tipoPesquisa=aluno";
	}
	
	@RequestMapping("/excluirAluno")
	public String excluirAluno(Aluno aluno) throws SQLException, Exception {
		new DAOGenerico<Aluno>(new ConnectionFactory().getConnection()).excluir(aluno, "idAluno");
		return "forward:pesquisaAvancada?tipoPesquisa=aluno";
	}

}
